<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item v-if="showMs">
          <el-select
            v-model="dataForm.homestayId"
            placeholder="关联民宿"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in homestays"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="showMs">
          <el-select
            v-model="dataForm.islandId"
            placeholder="所属区域"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in scenicOptions"
              :key="item.id"
              :label="item.scenicName"
              :value="item.scenicName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.jointName"
            placeholder="套票名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="" prop="startPortNo">
          <el-select
            style="width: 100%"
            v-model="dataForm.startPortNo"
            placeholder="出发港口"
            clearable
          >
            <el-option
              v-for="(item, index) in startOptions"
              :key="index"
              :value="item.portName"
              :label="item.portName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="endPortNo">
          <el-select
            style="width: 100%"
            v-model="dataForm.endPortNo"
            placeholder="到达港口"
            clearable
          >
            <el-option
              v-for="(item, index) in endOptions"
              :key="index"
              :value="item.portName"
              :label="item.portName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.guestName"
            placeholder="联系人"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.guestPhone"
            placeholder="联系方式"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.status" placeholder="订单状态" clearable>
            <el-option
              :value="item.val"
              v-for="item in payState"
              :key="item.val"
              :label="item.label"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.orderCode"
            placeholder="订单编号"
            clearable
          ></el-input>
        </el-form-item>
        <!-- 支付时间 -->
        <el-form-item>
          <el-date-picker
            v-model="value1"
            type="datetimerange"
            range-separator="至"
            start-placeholder="下单开始日期"
            end-placeholder="下单结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <!-- 核销时间 -->
        <el-form-item>
          <el-date-picker
            v-model="value2"
            type="datetimerange"
            range-separator="至"
            start-placeholder="核销开始日期"
            end-placeholder="核销结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
        :height="he"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          fixed="left"
          prop="orderCode"
          label="订单编号"
          header-align="center"
          align="center"
          min-width="200"
        ></el-table-column>
        <el-table-column
          prop="jointName"
          label="套票名称"
          header-align="center"
          :show-overflow-tooltip="true"
          min-width="180"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="islandName"
          label="所属区域"
          header-align="center"
          :show-overflow-tooltip="true"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="homestayName"
          label="民宿名称"
          header-align="center"
          :show-overflow-tooltip="true"
          min-width="160"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="startPortName"
          label="起始港口"
          sortable="custom"
          header-align="center"
          align="center"
          :show-overflow-tooltip="true"
          min-width="120"
        ></el-table-column>
        <el-table-column
          prop="endPortName"
          label="停靠港口"
          sortable="custom"
          header-align="center"
          align="center"
          :show-overflow-tooltip="true"
          min-width="120"
        ></el-table-column>
        <el-table-column
          prop="guestName"
          label="联系人"
          header-align="center"
          align="center"
          min-width="100"
        ></el-table-column>
        <el-table-column
          prop="guestPhone"
          label="联系电话"
          header-align="center"
          align="center"
          min-width="120"
        ></el-table-column>
        <el-table-column
          prop="status"
          label="订单状态"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              :style="{
                background: statusColor[scope.row.status],
                color: '#fff',
              }"
              >{{ scope.row.status | delStatus }}</el-button
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="orderAmount"
          label="套餐价格"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
         <el-table-column
          prop="realityPay"
          label="实付金额"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="orderTime"
          label="下单时间"
          header-align="center"
          align="center"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="updateDate"
          label="核销时间"
          header-align="center"
          align="center"
          width="180"
        >
        <template slot-scope="scope">
          {{scope.row.status==3?scope.row.updateDate:''}}
        </template>
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <!-- <el-button
              type="text"
              size="small"
              v-if="$hasPermission('hotel:ticketpackage:update')"
              @click="addOrUpdateHandle(scope.row.id)"
              >{{ $t("update") }}</el-button
            > -->
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('hotel:hotelorder:delete')"
              @click="deleteHandle(scope.row.id)"
              >{{ $t("delete") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></add-or-update>
    </div>
  </el-card>
</template>

<script>
var that;
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./hotel-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/hotel/ticket/package/getHotelJointOrderPage",
        getDataListIsPage: true,
          deleteURL:'/hotel/order',
        deleteIsBatch:true
      },
      he:'auto',
      showMs: false,
      startOptions: [],
      endOptions: [],
      scenicOptions: [],
      homestays: [],
      value1: [],
      value2: [],
      statusColor: {
        0: "#FF4141",
        1: "#409eff",
        "-1": "#CCC",
        "-2": "#FF9C3D",
        "-3": "#CCC",
        3: "#CCC",
      },
      payState: [
        {
          val: 3,
          label: "已完成",
        },
        {
          val: -3,
          label: "已退款",
        },
        {
          val: -2,
          label: "退款中",
        },
        {
          val: -1,
          label: "已取消",
        },
        {
          val: 1,
          label: "已支付",
        },
        {
          val: 0,
          label: "待支付",
        },
      ],
      dataForm: {
        endPortNo: "",
        homestayId: this.$store.state.user.homestayId || "",
        islandId: "",
        jointName: "",
        startPortNo: "",
        status: "",
        orderTimeEnd: "",
        orderTimeStart: "",
        updateEndDate: "",
        updateOpenDate: "",
        orderCode: "",
        guestName: "",
        guestPhone: "",
      },
    };
  },
  components: {
    AddOrUpdate,
  },
  filters: {
    delStatus(val) {
      let d = that.payState.filter((item) => item.val == val);
      if (d[0]) {
        return d[0].label;
      } else {
        return "";
      }
    },
  },
  watch: {
    dataList(newval, oldval) {
      if (newval != oldval) {
        this.he = "auto";
        setTimeout(() => {
          this.he = "calc(100vh - 330px)";
        }, 500);
      }
    },
    value1(newval, oldval) {
      if (newval) {
        if (newval != oldval) {
          this.dataForm.orderTimeStart = newval[0];
          this.dataForm.orderTimeEnd = newval[1];
        }
      } else {
        this.dataForm.orderTimeStart = "";
        this.dataForm.orderTimeEnd = "";
      }
    },
    value2(newval, oldval) {
      if (newval) {
        if (newval != oldval) {
          this.dataForm.updateOpenDate = newval[0];
          this.dataForm.updateEndDate = newval[1];
        }
      } else {
        this.dataForm.updateOpenDate = "";
        this.dataForm.updateEndDate = "";
      }
    },
  },
  created() {
    that = this;
    Promise.all([this.queryOption(0), this.queryOption(1)]).then(() => {
      this.dataForm.startPortNo = null;
      this.dataForm.endPortNo = null;
    });
    this.getHomestay();
    this.getScenicOptions();
    if (
      this.$store.state.user.roleList &&
      this.$store.state.user.roleList.indexOf("1712742759269081090") > -1
    ) {
      this.showMs = true;
    }
  },
  methods: {
    getHomestay() {
      this.$http
        .get("/hotel/homestay/getHomestayDownBox")
        .then(({ data: res }) => {
          if (res.code == 0) {
            this.homestays = res.data;
          }
        });
    },
    getScenicOptions() {
      this.$http
        .get("scenic/isscenic/selectScenicList", {})
        .then(({ data: res }) => {
          if (res.msg == "success") {
            this.scenicOptions = res.data;
          }
        });
    },
    //港口
    queryOption(type) {
      this.$http
        .get("/travel/isshipport/listPort", {
          params: {
            type: type,
          },
        })
        .then(({ data: res }) => {
          switch (type) {
            case 0:
              this.startOptions = res.data;
              break;
            case 1:
              this.endOptions = res.data;
              break;
          }
        });
    },
  },
};
</script>
